package com.pf.java.fanxing;

import java.util.ArrayList;
import java.util.List;

/**
 * 泛型方法
 *
 * @author pf
 * @data 2021/11/2-16:16
 */
public class Generic6 {
    public static void main(String[] args) {
        String[] nameArray = {"2", "aa" ,"vv"};
        List<String> list = new ArrayList<>();
        arrayToList(nameArray, list);
        System.out.println(list);

        // 不要制造迷惑的场景
//        Integer[] num = {1,2,3,4};
//        List<Double> numlist = new ArrayList<>();
//        arrayToList(num, numlist);
    }

    public static <T> void arrayToList(T[] array, List<T> list) {
        if (array == null || list ==null) {
            return;
        }

        for (T t : array) {
            list.add(t);
        }

    }
}
